package com.wyd.qxglmybatis.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.wyd.qxglmybatis.dto.UsersDTO;
import com.wyd.qxglmybatis.model.Users;
import com.wyd.qxglmybatis.service.IUsersService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/users")
public class UsersController {


    @Resource
    private IUsersService usersService;


    @ApiOperation(value = "分页条件查询",notes = "分页条件查询")
    @GetMapping(value = "findAll")
    public Map findAll(UsersDTO dto){


        List<Users> list =usersService.findAll(dto);

        Map<String,Object> map=new HashMap<String,Object>();

        map.put("msg", "成功");
        map.put("code", "0");
        map.put("count", usersService.getCount(dto));
      
        map.put("data", list);

        return map;
    }

   // @ApiOperation(value = "修改用户",notes = "修改用户")
    

    /* @ApiImplicitParams({
        @ApiImplicitParam(name="id",value ="会员编号",required=true,paramType ="path"),
        @ApiImplicitParam(name="login_name",value ="登录名",required=true,paramType ="path"),
        @ApiImplicitParam(name="protectemail",value ="邮箱",required=true,paramType ="path"),
        @ApiImplicitParam(name="protectmtel",value ="手机号",required=true,paramType ="path")

    })
    @PutMapping(value = "edit")
    public int editUser(@PathVariable String id,@PathVariable String login_name,@PathVariable String protectemail,@PathVariable String protectmtel) {
        
        return usersService.editUser(id,login_name,protectemail,protectmtel);
        
    } */
        

    @ApiOperation(value = "添加或修改用户",notes = "添加或修改用户")
    @PostMapping(value = "addOrEdit")
    public int addOrEdit(@RequestBody Users u){

        return usersService.addOrEditUser(u);

    }

  @ApiOperation(value = "删除用户",notes = "删除用户")
    @DeleteMapping(value = "del")
    public int del( String  id){

        return usersService.del(id);

    }


    @ApiOperation(value = "批量删除用户",notes = "批量删除用户")
    @DeleteMapping(value = "delAll")
    public void delAll( String[]  id){

         usersService.deleteCTQ(id);

    }


 @ApiOperation(value = "用户重置密码",notes = "用户重置密码")
   @PutMapping(value = "reset")
    public int resetPWD( String  id){

       return  usersService.resetPWD(id);

    }


    @ApiOperation(value = "锁定用户",notes = "锁定用户")
    @PutMapping(value = "lock")
     public int lock( String  id){
 
        return  usersService.lockUser(id);
 
     }


     @ApiOperation(value = "解锁用户",notes = "解锁用户")
     @PutMapping(value = "unlock")
      public int unlock( String  id){
  
         return  usersService.unLockUser(id);
  
      }


}